﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

using BusinessManagementStudio.Models.BusinessObject.Entities;
using MongoDB.Driver.Builders;
using MongoDB.Driver.Linq;

namespace BusinessManagementStudio.Models.BusinessObject.Services
{
    public class ContractorAssignmentService : EntityService<ContractorAssignment>
    {
        public List<ContractorAssignment> GetAllContractors()
        {
            return (from contractorAssign in this.MongoConnectionHandler.MongoCollection.FindAllAs<ContractorAssignment>()
                    select contractorAssign).ToList();
        }

        public ContractorAssignment GetSubContAssignment_ByQuotationNo(String QuotationNo)
        {
            return (from contractorAssign in this.MongoConnectionHandler.MongoCollection.FindAllAs<ContractorAssignment>()
                    where contractorAssign.QuotationNo == QuotationNo
                    select contractorAssign).FirstOrDefault();
        }

        public override void Update(ContractorAssignment entity)
        {
            this.MongoConnectionHandler.MongoCollection.Update(
                    Query<ContractorAssignment>.EQ(o => o.QuotationNo, entity.QuotationNo),
                    Update<ContractorAssignment>.Set(o => o.Material, entity.Material)
                    .Set(o => o.Remarks, entity.Remarks)
                    .Set(o => o.SubConAmountInHKD, entity.SubConAmountInHKD));
        }
    }
}